#ifndef _FF_WRAP_H_
#define _FF_WRAP_H_

#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>

#define FF_CODEC_OPEN 	0
#define STREAM_SAMPLE_FMT AV_SAMPLE_FMT_FLTP
#define STREAM_PIX_FMT    AV_PIX_FMT_YUV420P /* default pix_fmt */

typedef struct ff_context
{
	AVFormatContext *fmt_ctx;
	int video_stream_idx;
	int audio_stream_idx;
	AVStream *audio_st;
	AVStream *video_st;
	AVCodec *audio_codec;
	AVCodec *video_codec;
	int vframe_cnt;
	int aframe_cnt;
	AVPacket pkt;
}st_ff_context;

/**
 * initialize muxer configuration,include AVFormatContext,AVCodecContext .etc 
 * @param[in] filename the record file name
 * @param[in,out] ff_ctx FFmpeg user-defined context information
 * @param[in] param media and control parameter to set AVCodecContext,can be
 * NULL
 * @return success return 0,or < 0
 */
int ff_init_muxer(const char *filename, st_ff_context *ff_ctx,void *param);
int ff_exit_muxer(st_ff_context *ff_ctx);

/**
 *  write a audio frame to file
 * 	@param[in] ff_ctx ffmpeg library context inited by ff_init_muxer
 * 	@param[in] data the encoded audio frame data
 * 	@param[in] len the encoded audio frame length
 * 	@return if success 0, or -1.
 */
int ff_write_audio_frame(st_ff_context *ff_ctx, unsigned char *data,int len);
/**
 *  write a video frame to file
 * 	@param[in] ff_ctx ffmpeg library context 
 * 	@param[in] data the encoded video frame data
 * 	@param[in] len the encoded video frame length
 * 	@return if success 0, or -1.
 */
int ff_write_video_frame(st_ff_context *ff_ctx, unsigned char *data,int len);

int ff_init_demuxer(const char *filename, st_ff_context *ff_ctx);
int ff_exit_demuxer(st_ff_context *ff_ctx);

#endif

